package com.neusoft.mapper;

import com.neusoft.po.RedPacket;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface RedPacketMapper {
    //get redpacket by packetId
    @Select("select * from redpacket where packetId=#{packetId}")
    public RedPacket getRedPacketByPacketId(int packetId);
    
    //update redpacket deleted=1 by packetId
    @Update("update redpacket set deleted=1 where packetId=#{packetId}")
    public int deleteRedPacketByPacketId(int packetId);
	
    //get total redpacket by userId and not deleted
    @Select("select * from redpacket_copy where userId=#{userId} and deleted=0")
    public List<RedPacket> getTotalRedPacketByUserId(String userId);

    //get redpacket by userId
    @Select("select * from redpacket where userId=#{userId}")
    public List<RedPacket> getRedPacketByUserId(String userId);

    //get redpacket by userId and channelType
    @Select("select * from redpacket where userId=#{userId} and channelType=#{channelType}")
    public List<RedPacket> getRedPacketByUserIdAndChannelType(String userId, int channelType);

    //insert redpacket
    @Insert("insert into redpacket(userId, num, channelType, createTime,expiredTime, deleted) values(#{userId}, #{num}, #{channelType}, #{createTime},#{expiredTime},0)")
    @Options(useGeneratedKeys = true, keyProperty = "packetId", keyColumn = "packetId")
    public int insertRedPacket(RedPacket redPacket);

    @Insert("insert into redpacket_copy(userId, num, channelType, createTime,expiredTime, deleted) values(#{userId}, #{num}, #{channelType}, #{createTime},#{expiredTime},0)")
    @Options(useGeneratedKeys = true, keyProperty = "packetId", keyColumn = "packetId")
    public int insertRedPacketCopy(RedPacket redPacket);

    //update redpacket_copy deleted=1 by packetId
    @Update("update redpacket_copy set deleted=1 where packetId=#{packetId}")
    public int deleteRedPacketCopyByPacketId(int packetId);

    //update redpacket_copy set num=leftnum by packetId
    @Update("update redpacket_copy set num=#{leftNum} where packetId=#{packetId}")
    public int updateRedPacketCopyByPacketId(@Param("packetId") int packetId, @Param("leftNum") Double leftNum);
}
